package com.bilibili.xzz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.bilibili.xzz.entity.MessageBoard;
import com.bilibili.xzz.mapper.MessageBoardMapper;
import com.bilibili.xzz.service.MessageBoardService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MessageBoardServiceImpl implements MessageBoardService {

    @Resource
    MessageBoardMapper messageBoardMapper;

    @Override
    public MessageBoard getMessageBoardById(Long id) {
        return messageBoardMapper.selectById(id);
    }

    @Override
    public List<MessageBoard> getAllMessageBoard() {
        return messageBoardMapper.selectList(new QueryWrapper<MessageBoard>().orderByDesc("is_top").eq("is_checked",1));
    }

    @Override
    public List<MessageBoard> getCheckedMessageBoard() {
        return messageBoardMapper.selectList(new QueryWrapper<MessageBoard>().orderByDesc("is_top").eq("is_checked",0));
    }

    @Override
    public int insertMessageBoard(MessageBoard messageBoard) {
        return messageBoardMapper.insert(messageBoard);
    }

    @Override
    public int updateMessageBoard(String id,Integer agree) {
        return messageBoardMapper.update(null,new UpdateWrapper<MessageBoard>().eq("id",id).set("agree",agree+1));
    }

    @Override
    public int disagreeMessageBoard(String id, Integer disagree) {
        return messageBoardMapper.update(null,new UpdateWrapper<MessageBoard>().eq("id",id).set("disagree",disagree+1));
    }

    @Override
    public int deleteMessage(String name) {
        return messageBoardMapper.delete(new QueryWrapper<MessageBoard>().eq("name",name));
    }

    @Override
    public int setTop(MessageBoard messageBoard) {
        return messageBoardMapper.updateById(messageBoard);
    }

    @Override
    public int setChecked(MessageBoard messageBoard) {
        return messageBoardMapper.updateById(messageBoard);
    }
}
